/*-
 * Copyright (C) 2018-2020, Shanghai Trusted Industry Control Platform Co., Ltd.
 * Created by 周正辉 (Zhenghui Zhou) <zhouzhenghui@ticpsh.com>, 赵楷文 (Kaiwen
 * Zhao) <zhaokaiwen@ticpsh.com>
 */

#ifndef TESTHELPER_H
#define TESTHELPER_H

#include <clang/AST/ASTConsumer.h>
#include <clang/AST/Mangle.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Basic/SourceManager.h>
#include <llvm/Support/raw_os_ostream.h>

#include <boost/filesystem.hpp>
#include <iostream>
#include <map>
#include <nlohmann/json.hpp>
#include <set>
#include <vector>

namespace rocket {
namespace testif {

struct FuncDeclInfo {
  std::set<const clang::CXXMethodDecl *> overridings;
};

std::string source_location_string(const clang::SourceManager &sm,
                                   clang::SourceLocation loc);

std::string getNamedDeclName(const clang::NamedDecl *nd);

std::vector<std::string> getFuncAttrs(const clang::FunctionDecl *fd);

bool isContainAttr(const nlohmann::json &attributes,
                   const std::string &attribute);

struct CodeLineInfo {
  std::map<unsigned, unsigned> code_lines;
  std::map<unsigned, unsigned> comment_lines;
  std::map<unsigned, unsigned> not_blank_lines;

  void addCodeLine(unsigned line) { code_lines.emplace(line, 1); }
  void addCommentLine(unsigned line) { comment_lines.emplace(line, 1); }
};
CodeLineInfo getCodeLineInfoInRange(clang::SourceRange range,
                                    clang::ASTContext &ast);

}  // namespace testif
}  // namespace rocket

#endif  // TESTHELPER_H
